#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e5 + 10, mod = 998244353;

ll n, m;
vector<ll> g[N];
ll f[N], d[N], in[N];

void dfs(ll x)
{
    if (d[x]) return;
    d[x] = 1;
    for (ll y : g[x]) {
        dfs(y);
        (d[x] += d[y]) %= mod;
        (f[x] += (f[y] + d[y])) %= mod;
    }
}

ll ksm(ll a, ll b)
{
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;b >>= 1;
    }
    return res;
}

void solve()
{
    cin >> n >> m;
    for (ll i = 1;i <= m;i++) {
        ll x, y;cin >> x >> y;
        g[x].push_back(y);
        in[y]++;
    }

    for (ll i = 1;i <= n;i++) if (in[i] == 0) dfs(i);
    ll len = 0, cnt = 0;
    for (ll i = 1;i <= n;i++) (len += f[i]) %= mod, (cnt += d[i]) %= mod;
    cout << len * ksm(cnt, mod - 2) % mod;
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}